package com.niit.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.service.UserService;
import com.niit.service.impl.UserServiceImpl;


@WebServlet("/CheckUserContorller")
public class CheckUserContorller extends HttpServlet {
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String fb = request.getParameter("forbid");
		boolean forbid = false;
		if(fb.equals("true")){
			forbid = true;
			}		
		UserService us = new UserServiceImpl();
		int a =us.update(forbid, username);
		if(a==0){
			if(forbid==true){
				response.getOutputStream().write("解锁失败".getBytes());
			}else{
				response.getOutputStream().write("禁用失败".getBytes());
			}			
		}else if(a==1){
			if(forbid==true){
				response.getOutputStream().write("解锁成功".getBytes());
			}else{
				response.getOutputStream().write("禁用成功".getBytes());
			}
		}
	}

}
